<?php
namespace app\index\behavior;

use think\Log;
use Illuminate\Database\Capsule\Manager as Capsule;
class Start
{
    public function appBegin()
    {


$capsule = new Capsule;

$database_config = \think\Config::get('database');

$capsule->addConnection([
    'driver'    => 'mysql',
    'host'      => $database_config['hostname'],
    'database'  => $database_config['database'],
    'username'  => $database_config['username'],
    'password'  => $database_config['password'],
    'charset'   => $database_config['charset'],
    'collation' => 'utf8_unicode_ci',
    'prefix'    => $database_config['prefix'],
]);

// Set the event dispatcher used by Eloquent models... (optional)
// use Illuminate\Events\Dispatcher;
// use Illuminate\Container\Container;
$capsule->setEventDispatcher(new \Illuminate\Events\Dispatcher(new \Illuminate\Container\Container));

// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
    }
}